package config

import (
	"alarm_service/common/logger"
	"embed"
	_ "embed"
	"gopkg.in/yaml.v3"
)

//go:embed config.yaml
var configFile embed.FS

type Database struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	Name     string `yaml:"name"`
}

type Config struct {
	DB Database `yaml:"mysql"`
}

func New() *Config {
	var config Config
	yamlFile, err := configFile.ReadFile("config.yaml")
	if err != nil {
		panic("Can not init config file " + err.Error())
	}
	if err := yaml.Unmarshal(yamlFile, &config); err != nil {
		panic("Can not init config file " + err.Error())
	}
	logger.Infof("config init", config.DB.Host)
	return &config
}
